<script type="text/javascript" src="../js/bdMap.js"></script>
<div style="width:100%;height:200px;">
    <table id="admin_shebei_info" data-options="fit:true"></table>
    <div id="shebei_info_toolbar" style="padding:0 10px; height:35px;line-height:35px;">
		<input class="icon-reload" type="button" value="刷新" onclick="flushAdd()"
			style="padding:3px 3px 3px 20px;border:1px #999 solid;margin:2px;border-radius:5px;"/>
		<input class="icon-reload" type="button" value="停用设备" onclick="AddModify()"
			style="padding:3px 3px 3px 20px;border:1px #999 solid;margin:2px;border-radius:5px;"/>
	</div>
</div>
<script type="text/javascript">
$(function(){
	$('#admin_shebei_info').datagrid({
		url:'../shebeiInfo/LocationInfo_getLocationInfo',
		loadMsg:'数据加载中...',
		fitColumns:true,
		rownumbers:true,
		striped:true,
		sortName:'lid',
		sortOrder:'asc',
		remoteSort:false,
		columns:[[
			{field:'sids',title:'',width:100,align:'center',checkbox:true},
			{field:'lid',title:'编号',width:100,align:'center',sortable:true},
			{field:'sname',title:'设备名称',width:100,align:'center'}, 
			{field:'laddr',title:'设备位置',width:200,align:'center'}, 
			{field:'lstatus',title:'设备状态',width:100,align:'center',formatter:function(value,rowData,rowIndex){
				if(value==1) {
					return "正常";
				} else if(value==0){
					return "停用";
				} else {
					return "维护";
				}
			}},
			{field:'_operate',title:'操作',width:100,align:'center',formatter:function(value, rowData, index){
				return "<a class='icon-file icon-padding' href=\"javascript:showInMap('"+rowData.sname+"/"+rowData.laddr+"/"+rowData.lstatus+"')\">在地图上显示</a>";
			}}
		]],
		toolbar:"#shebei_info_toolbar"
	});
});

//在地图中显示
function showInMap(val){
	var info=val.split("/");
	showInfoInMap(info);
}

//添加设备信息
function addShebeiInfo() {
	var sid=$("#add_sid").val();
	var sname=$("#add_sname").find("option:selected").text();
	var lng=$("#add_lng").val();
	var lat=$("#add_lat").val();
	var street=$("#add_motor").val();
	var position=street+"-("+lng+","+lat+")";
	if(sid!="" && (sname!=""||sname!="-- 请选择 --") && lng!="" && lat!="" && street!="") {
		$.post("../shebeiInfo/LocationInfo_addLocationInfo",{"li.sname":sname,"li.laddr":position},function(data){
			if(parseInt(data.result) > 0) {
				$.messager.show({
					title:'成功提示',
					msg:'添加成功!',
					timeout:3000,
					showType:'slide'
				});
				$("#add_sid").val("");
				$("#add_sname").val("");
				$("#add_lng").val("");
				$("#add_lat").val("");
				$("#add_motor").val("");
				$("#add_shebei_info").dialog("close");
				$('#admin_shebei_info').datagrid("reload");
			} else {
				$.messager.alert('错误提示','设备信息添加失败!','error');
			}
		});
	} else {
		$.messager.show({
			title:'温馨提示',
			msg:'您输入的信息不完整，请确认后再提交!',
			timeout:3000,
			showType:'slide'
		});
	}
}

function AddModify() {
	var lids=$('#admin_shebei_info').datagrid('getSelections');
	if(lids.length==0){
		$.messager.alert('错误提示','请选择删除项!','error');
		return;
	}
	if(lids.length>1){
		$.messager.alert('错误提示','请逐条操作!','error');
		$('#admin_shebei_info').datagrid('clearSelections');
	}else{
		$.post("../shebeiInfo/LocationInfo_modifyLocation",{"li.lid":lids[0].lid,"li.sname":lids[0].sname},function(data) {
	    	if(parseInt($.trim(data.result))==1){
	    		$.messager.show({
					title:'成功提示',
					msg:'修改信息成功！',
					timeout:3000,
					showType:'slide'
				});
				$('#admin_shebei_info').datagrid("reload");
	    	}else{
	    		$.messager.alert('错误提示','网络错误,请稍后重试!','error');
	    	}
	    });
	}
}

//刷新
function flushAdd() {
	init();
	$('#admin_shebei_info').datagrid("reload");
}

</script>
<div id="allmap" style="width:100%;height:100%;overflow:hidden;"></div>
<div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
<div id="add_shebei_info" class="easyui-dialog" title="添加设备位置信息" style="width:400px;height:300px;"
	data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
	<p style="width:100%;text-align:center;">
		<br /> <br /> 
		<label for="add_sid">设备编号：</label><input type="text" id="add_sid" disabled="disabled">
		<br /> <br /> 
		<label for="add_sname">设备名称：</label><select style="width:130px;text-align: center;" id="add_sname">
			<option>-- 请选择 --</option>
		</select>
		<br /> <br />
		<label for="add_lng">经&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;度：</label><input type="text" id="add_lng">
		<br /> <br />
		<label for="add_lat">纬&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;度：</label><input type="text" id="add_lat">
		<br /> <br />
		<label for="add_motor">道路名称：</label><input type="text" id="add_motor">
		<br /> <br />
		<input style="padding:5px 25px;" type="button" onclick="addShebeiInfo()" value="添&nbsp;&nbsp;&nbsp;&nbsp;加">
	</p>
</div>